package cc.mrbird.submission.controller;

import cc.mrbird.common.annotation.Log;
import cc.mrbird.common.controller.BaseController;
import cc.mrbird.common.domain.QueryRequest;
import cc.mrbird.common.domain.ResponseBo;
import cc.mrbird.handle.domain.Handle;
import cc.mrbird.handle.service.HandleService;
import cc.mrbird.submission.domain.PullDown;
import cc.mrbird.submission.domain.SubmissionEntry;
import cc.mrbird.submission.service.SubmissionService;
import cc.mrbird.submission.util.RestUtil;
import cc.mrbird.submission.util.WXPayUtil;
import cc.mrbird.system.service.UserRoleService;
import org.apache.poi.hssf.usermodel.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class SubmissionController extends BaseController {

    @Value("${uploadPath}")
    private String uploadPath;

    @Autowired
    private SubmissionService submissionService;
    @Autowired
    private UserRoleService userRoleService;
    @Autowired
    private HandleService handleService;

    private String cityparvm = null;

    @RequestMapping("submission")
    public String submission(Model model,SubmissionEntry submissionEntry) {
        String city = submissionEntry.getCity();
        cityparvm = city;
        return "submission/submission";
    }
    @Log("增加投诉信息")
    @RequestMapping("submission/addSubmission")
    @ResponseBody
    public ResponseBo addSubmission(HttpServletRequest request, SubmissionEntry submissionEntry, @RequestPart(value="pic",required = false) MultipartFile pic) throws Exception {
        if(submissionEntry.getPaymentChannels().equals("undefined")){
            submissionEntry.setPaymentChannels(null);
        }
        if(submissionEntry.getComplaintChannels().equals("undefined")){
            submissionEntry.setComplaintChannels(null);
        }
        if(submissionEntry.getComplaintLine().equals("undefined")){
            submissionEntry.setComplaintLine(null);
        }
        if(submissionEntry.getProcessingResults().equals("undefined")){
            submissionEntry.setProcessingResults(null);
        }
        if(submissionEntry.getComplaintType().equals("undefined")){
            submissionEntry.setComplaintType(null);
        }
        if(submissionEntry.getDutyDetermine().equals("undefined")){
            submissionEntry.setDutyDetermine(null);
        }
        if(submissionEntry.getContactInformation().equals("undefined")){
            submissionEntry.setContactInformation(null);
        }
        if(submissionEntry.getRegistrar().equals("undefined")){
            submissionEntry.setRegistrar(null);
        }
        if(submissionEntry.getHandler().equals("undefined")){
            submissionEntry.setHandler(null);
        }
        if(submissionEntry.getRemakes().equals("undefined")){
            submissionEntry.setRemakes(null);
        }
        if(submissionEntry.getContentsComplaints().equals("undefined")){
            submissionEntry.setContentsComplaints(null);
        }
        if(submissionEntry.getProcessing().equals("undefined")){
            submissionEntry.setProcessing("26");
        }
        if(submissionEntry.getFirst().equals("undefined")){
            submissionEntry.setFirst("48");
        }

        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(currentTime);
        submissionEntry.setAcceptanceTime(dateString);
        String num = submissionEntry.getCity();
        submissionEntry.setCity(num);
        submissionEntry.setFeedback(null);
        if(pic != null){
            String str = pic.getOriginalFilename();
            //截取图片名字之前字符串
            String str1=str.substring(0, str.indexOf("."));
            String frontPicName = str1+String.valueOf((int)((Math.random()*9+1)*1000000000));
            //截取图片名字之后字符串
            String str2=str.substring(0, str.indexOf("."));
            String afterPicName = str.substring(str2.length()+1, str.length());

            String picName = uploadPath + frontPicName+"."+afterPicName;
            File picFile = new File(picName);
            pic.transferTo(picFile);
            submissionEntry.setPicName(frontPicName+"."+afterPicName);
        }
        submissionService.saveSubmissionEntry(submissionEntry);
        String subid = submissionService.findId();
        Long id = super.getCurrentUser().getUserId();
        //190
        if(id == 190){
            WXPayUtil wxPayUtil = new WXPayUtil();
            Map map = new HashMap();
            String idNotice="";
            String content = null;
            if(cityparvm.equals("40")){
                if(submissionEntry.getFirst().equals("48")){
                    content = "你好，三亚前台人员有提交新的投诉信息，投诉编号为："+subid+"，请注意查看";
                }else if(submissionEntry.getFirst().equals("47")){
                    content = "你好，优先处理的投诉信息工单，投诉编号为："+subid+"，请注意查看！";
                }
                idNotice = "111";
            }else if(cityparvm.equals("41")){
                if(submissionEntry.getFirst().equals("48")){
                    content = "你好，陵水前台人员有提交新的投诉信息，投诉编号为："+subid+"，请注意查看";
                }else if(submissionEntry.getFirst().equals("47")){
                    content = "你好，优先处理的投诉信息工单，投诉编号为："+subid+"，请注意查看！";
                }

                 idNotice = "93";
            }
            String keyid = "2";
            String random_number = wxPayUtil.generateNonceStr();
            String time_stamp = String.valueOf(System.currentTimeMillis());
            String key = "EL6UjSc4U1it6vaFrQ9GlGiMicEbRc0P";
            //通知编号
            map.put("id",idNotice);
            //通知内容
            map.put("content",content);
            //keyid
            map.put("keyid",keyid);
            //随机数
            map.put("random_number",random_number);
            //时间戳
            map.put("time_stamp",time_stamp);
            String sign = wxPayUtil.generateSignature(map,key);
            String url = "http://120.77.182.149:8999/OpenApi/tyxNotice";
            System.out.println(url);
            String data = "id="+idNotice+"&content="+content+"&keyid="+keyid+"&random_number="+random_number+"&time_stamp="+time_stamp+"&sign="+sign;

            RestUtil restUtil = new RestUtil();
            restUtil.interfaceUtil(url,data);
        }
        return ResponseBo.ok();
    }

    @Log("获取投诉信息列表")
    @RequestMapping("submission/submissionList")
    @ResponseBody
    public Map<String, Object> submissionList(QueryRequest request, SubmissionEntry submissionEntry) {
        System.out.println(submissionEntry.getFirst());
        submissionEntry.setCity(cityparvm);
        return super.selectByPageNumSize(request, () -> this.submissionService.getSubmissionEntryList(submissionEntry));
    }


    @Log("获取投诉信息优先处理列表")
    @RequestMapping("submission/submissionFirstList")
    @ResponseBody
    public Map<String, Object> submissionFirstList(QueryRequest request, SubmissionEntry submissionEntry) {
        System.out.println(submissionEntry.getFirst());
        submissionEntry.setCity(cityparvm);
        return super.selectByPageNumSize(request, () -> this.submissionService.getSubmissionEntryList(submissionEntry));
    }

    @Log("根据id获取投诉信息")
    @RequestMapping("submission/getBySubmissionId")
    @ResponseBody
    public ResponseBo getBySubmissionId(SubmissionEntry submissionEntry) {
        String id = submissionEntry.getId();
        submissionEntry.setId(id);
        submissionEntry.setCity(cityparvm);
        return ResponseBo.ok().put("data",submissionService.getBySubmissionId(submissionEntry));
    }

    @Log("修改投诉信息")
    @RequestMapping("submission/updateSubmission")
    @ResponseBody
    public ResponseBo updateSubmission(SubmissionEntry submissionEntry,@RequestPart(value="pic",required = false) MultipartFile pic) throws Exception {
        if(submissionEntry.getProcessingResults().equals("undefined")){
            submissionEntry.setProcessingResults(null);
        }
        if(submissionEntry.getHandler().equals("undefined")){
            submissionEntry.setHandler(null);
        }
        if(pic != null){
            String str = pic.getOriginalFilename();
            //截取图片名字之前字符串
            String str1=str.substring(0, str.indexOf("."));
            String frontPicName = str1+String.valueOf((int)((Math.random()*9+1)*1000000000));
            //截取图片名字之后字符串
            String str2=str.substring(0, str.indexOf("."));
            String afterPicName = str.substring(str2.length()+1, str.length());

            String picName = uploadPath + frontPicName+"."+afterPicName;
            File picFile = new File(picName);
            pic.transferTo(picFile);
            submissionEntry.setPicName(frontPicName+"."+afterPicName);
        }
        Long id = super.getCurrentUser().getUserId();
        if(submissionEntry.getProcessing().equals("已处理")){
            submissionEntry.setFirst("48");
        }
        if(id == 190){
            submissionEntry.setProcessing("未处理");
        }
        System.out.println("处理状态：" + submissionEntry.getProcessing());
        if(submissionEntry.getProcessing().equals("已处理")||submissionEntry.getProcessing()=="已处理"){
            Date currentTime = new Date();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String dateString = formatter.format(currentTime);
            submissionEntry.setProcessingTime(dateString);
        }
        String processingTime = submissionEntry.getProcessingTime();
        if(processingTime == ""){
            System.out.println("processingTime: "+processingTime);
            submissionEntry.setProcessingTime(null);
        }
        submissionService.updateSubmission(submissionEntry);
        return ResponseBo.ok();
    }

    @Log("动态获取下拉选")
    @RequestMapping("submission/pullDown")
    @ResponseBody
    public List<PullDown> FindPullDown(PullDown pullDown ) {

            return submissionService.FindPullDown(pullDown);

    }
    @Log("增加选配置")
    @RequestMapping("submission/addPullDown")
    @RequiresPermissions("submission:addPullDown")
    @ResponseBody
    public ResponseBo addPullDown(PullDown pullDown )throws Exception {

        PullDown pullDown1 = submissionService.savePullDown(pullDown);
        if(pullDown1 == null){
            submissionService.addPullDown(pullDown);
            return ResponseBo.ok();
        }else{
            return ResponseBo.error("已存在！请重新填写");
        }
    }

    @Log("投诉信息撤销")
    @RequestMapping("submission/cancelSubmission")
    @RequiresPermissions("submission:cancelSubmission")
    @ResponseBody
    public ResponseBo cancelSubmission(SubmissionEntry submissionEntry )throws Exception{
        submissionEntry.setFirst("48");
        submissionService.cancelSubmission(submissionEntry);
        return ResponseBo.ok();
    }

    @Log("投诉信息通知技术员")
    @RequestMapping("submission/technology")
    @ResponseBody
    public ResponseBo technology(SubmissionEntry submissionEntry )throws Exception{
            Handle handle1 = new Handle();
            handle1.setId(submissionEntry.getId());
            List<Handle> handleList = handleService.getHandleList(handle1);
            if(handleList.size() == 0){
                SubmissionEntry submissionEntry1  = submissionService.getSubmissionEntry(submissionEntry);
                Handle handle = new Handle();
                handle.setId(submissionEntry.getId());
                handle.setAcceptanceTime(submissionEntry1.getAcceptanceTime());
                handle.setComplaintLine(submissionEntry1.getComplaintLine());
                handle.setPaymentChannels(submissionEntry1.getPaymentChannels());
                handle.setComplaintType(submissionEntry1.getComplaintType());
                handle.setContentsComplaints(submissionEntry1.getContentsComplaints());
                handle.setRemakes(submissionEntry1.getRemakes());
                handle.setProcessing("26");
                handle.setRegistrar(submissionEntry1.getRegistrar());
                handleService.saveHandle(handle);
                WXPayUtil wxPayUtil = new WXPayUtil();
                Map map = new HashMap();
                //通知三亚技术人员
                String idNotice = "109";
                //String idNotice = "94";
                String content = null;
                content = "你好，三亚人员有提交新的定位/故障信息，投诉编号为："+submissionEntry.getId()+"，请注意查看";
                String keyid = "2";
                String random_number = wxPayUtil.generateNonceStr();
                String time_stamp = String.valueOf(System.currentTimeMillis());
                String key = "EL6UjSc4U1it6vaFrQ9GlGiMicEbRc0P";
                //通知编号
                map.put("id",idNotice);
                //通知内容
                map.put("content",content);
                //keyid
                map.put("keyid",keyid);
                //随机数
                map.put("random_number",random_number);
                //时间戳
                map.put("time_stamp",time_stamp);
                String sign = wxPayUtil.generateSignature(map,key);
                String url = "http://120.77.182.149:8999/OpenApi/tyxNotice";
                System.out.println(url);
                String data = "id="+idNotice+"&content="+content+"&keyid="+keyid+"&random_number="+random_number+"&time_stamp="+time_stamp+"&sign="+sign;
                System.out.println("data:"+data);
                RestUtil restUtil = new RestUtil();
                restUtil.interfaceUtil(url,data);
                return ResponseBo.ok();
            }else{
                return ResponseBo.error("已经通知技术员，请不要重复通知");
            }
    }

    @Log("上传excel")
    @RequestMapping("submission/batchImport")
    @RequiresPermissions("submission:batchImport")
    @ResponseBody
    public boolean batchImport(@RequestParam("file") MultipartFile file) {
        boolean a = false;
        String fileName = file.getOriginalFilename();
        try {
            a = submissionService.batchImport(fileName, file);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  a;
    }
    /**
     * 导出投诉信息
     * @param response
     * @param submissionEntry
     * @return
     */
    @RequestMapping("submission/exportExcel")
    @ResponseBody
    public Object exportExcel(HttpServletResponse response, SubmissionEntry submissionEntry){

        ServletOutputStream outputStream = null;
        HSSFWorkbook workbook = null;
        try {
            // 创建 excel 文件
            workbook = new HSSFWorkbook();
            // 创建一个标签页
            HSSFSheet sheet = workbook.createSheet("用户信息");

            //设置列宽
            sheet.setColumnWidth(0, 3000);
            sheet.setColumnWidth(1, 3000);
            sheet.setColumnWidth(2, 3000);
            sheet.setColumnWidth(3, 3000);
            sheet.setColumnWidth(4, 3000);
            sheet.setColumnWidth(5, 3000);
            sheet.setColumnWidth(6, 3000);
            sheet.setColumnWidth(7, 3000);
            sheet.setColumnWidth(8, 3000);
            sheet.setColumnWidth(9, 3000);
            sheet.setColumnWidth(10, 3000);
            sheet.setColumnWidth(11, 3000);
            sheet.setColumnWidth(12, 3000);
            sheet.setColumnWidth(13, 3000);
            sheet.setColumnWidth(14, 3000);


            //创建格式
            HSSFCellStyle titleStyle = workbook.createCellStyle();
            titleStyle.setWrapText(true);
            titleStyle.setAlignment(HSSFCellStyle.VERTICAL_CENTER);//水平居中
            titleStyle.setVerticalAlignment(HSSFCellStyle.ALIGN_CENTER);//垂直居中


            HSSFFont titleFont = workbook.createFont();
            titleFont.setBold(true);//粗体
            titleFont.setFontHeightInPoints((short)12);//大小
            titleFont.setFontName("宋体");//字体类型
            titleStyle.setFont(titleFont);

            // 创建标题行
            HSSFRow titleRow = sheet.createRow(0);

            HSSFCell cell0 = titleRow.createCell(0);
            cell0.setCellValue("投诉编号");
            cell0.setCellStyle(titleStyle);

            HSSFCell cell1 = titleRow.createCell(1);
            cell1.setCellValue("受理时间");
            cell1.setCellStyle(titleStyle);

            HSSFCell cell2 = titleRow.createCell(2);
            cell2.setCellValue("支付渠道");
            cell2.setCellStyle(titleStyle);

            HSSFCell cell3 = titleRow.createCell(3);
            cell3.setCellValue("投诉渠道");
            cell3.setCellStyle(titleStyle);

            HSSFCell cell4 = titleRow.createCell(4);
            cell4.setCellValue("投诉类别");
            cell4.setCellStyle(titleStyle);

            HSSFCell cell5 = titleRow.createCell(5);
            cell5.setCellValue("联系方式");
            cell5.setCellStyle(titleStyle);

            HSSFCell cell6 = titleRow.createCell(6);
            cell6.setCellValue("投诉路线");
            cell6.setCellStyle(titleStyle);

            HSSFCell cell7 = titleRow.createCell(7);
            cell7.setCellValue("投诉内容");
            cell7.setCellStyle(titleStyle);

            HSSFCell cell8 = titleRow.createCell(8);
            cell8.setCellValue("责任判定");
            cell8.setCellStyle(titleStyle);

            HSSFCell cell9 = titleRow.createCell(9);
            cell9.setCellValue("处理结果");
            cell9.setCellStyle(titleStyle);

            HSSFCell cell10 = titleRow.createCell(10);
            cell10.setCellValue("登记人");
            cell10.setCellStyle(titleStyle);

            HSSFCell cell11 = titleRow.createCell(11);
            cell11.setCellValue("处理时间");
            cell11.setCellStyle(titleStyle);

            HSSFCell cell12 = titleRow.createCell(12);
            cell12.setCellValue("处理人");
            cell12.setCellStyle(titleStyle);

            HSSFCell cell13 = titleRow.createCell(13);
            cell13.setCellValue("公交公司");
            cell13.setCellStyle(titleStyle);

            HSSFCell cell14 = titleRow.createCell(14);
            cell14.setCellValue("处理情况");
            cell14.setCellStyle(titleStyle);

            HSSFCell cell15 = titleRow.createCell(15);
            cell15.setCellValue("城市");
            cell15.setCellStyle(titleStyle);

            //DB查询数据
            submissionEntry.setCity(cityparvm);
            System.out.println("城市："+cityparvm);
            List<SubmissionEntry> userList = submissionService.getSubmissionEntryExportExcel(submissionEntry);
            System.out.println(userList);
            if(userList == null || userList.isEmpty()){
                return ("导出数据失败，无投诉信息！");
            }


            // 封装excel数据
            DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            for (int i = 0; i < userList.size(); i++) {
                System.out.println(userList.size());
                titleRow = sheet.createRow(i + 1);
                //投诉编号
                titleRow.createCell(0).setCellValue(userList.get(i).getId());
                //受理时间
                titleRow.createCell(1).setCellValue(userList.get(i).getAcceptanceTime());
                //支付渠道
                titleRow.createCell(2).setCellValue(userList.get(i).getPaymentChannels());
                //投诉渠道
                titleRow.createCell(3).setCellValue(userList.get(i).getComplaintChannels());
                //投诉类别
                titleRow.createCell(4).setCellValue(userList.get(i).getComplaintType());
                //联系方式
                titleRow.createCell(5).setCellValue(userList.get(i).getContactInformation());
                //投诉线路
                titleRow.createCell(6).setCellValue(userList.get(i).getComplaintLine());
                //投诉内容
                titleRow.createCell(7).setCellValue(userList.get(i).getContentsComplaints());
                //责任判定
                titleRow.createCell(8).setCellValue(userList.get(i).getDutyDetermine());
                //处理结果
                titleRow.createCell(9).setCellValue(userList.get(i).getProcessingResults());
                //登记人
                titleRow.createCell(10).setCellValue(userList.get(i).getRegistrar());
                //处理时间
                titleRow.createCell(11).setCellValue(userList.get(i).getProcessingTime());
                //处理人
                titleRow.createCell(12).setCellValue(userList.get(i).getHandler());
                //公交公司
                titleRow.createCell(13).setCellValue(userList.get(i).getBusCompany());
                //处理情况
                titleRow.createCell(14).setCellValue(userList.get(i).getProcessing());
                //城市
                titleRow.createCell(15).setCellValue(userList.get(i).getCity());

            }
            // 设置两个头 一个输出流
            String filename = "投诉信息表.xls";
                try {
                    outputStream = response.getOutputStream();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                // 响应信息，弹出文件下载窗口
            response.setContentType("APPLICATION/OCTET-STREAM");
                try {
                    response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "utf-8"));
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                try {
                    workbook.write(outputStream);
                } catch (IOException e) {
                    e.printStackTrace();
                }

            return ResponseBo.error("导出数据失败！");
        } finally {
            try {
                if (outputStream != null) {
                    workbook.close();
                    outputStream.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
                return ResponseBo.error( "导出数据失败！" + e.getMessage());
            }

        }
    }

    /**
     * 每日报文
     * @return
     * @throws Exception
     *
     *
     * 今日投诉汇报：
     * 1、2021年04月16日，共接到投诉7条，其中电子支付6条，已处理2条，未处理4条；充电业务1条，已处理0条，未处理0条；智慧停车业务*条，已处理*条，未处理*条。
     * 2、昨日遗留投诉电子支付10条，充电业务0条，智慧停车业务*条。今日处理后仍遗留未处理投诉：电子支付4条，充电业务0条,智慧停车业务*条
     * 3、截止今日17:59:59，共遗留未处理投诉：电子支付10条，充电业务0条，智慧停车*条。
     * --------
     * 2021-04-16 18:00:00
     */
    @RequestMapping("submission/message")
    @Scheduled(cron = "0 0 18 * * ?")
    @ResponseBody
    public ResponseBo message() throws Exception {
        //d为当前日期
        Date d = new java.util.Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy年MM月dd日");
        String str1 = sdf1.format(d);
        String startTime11 = sdf.format(addDateDays(d,-1))+" 18:00:00";
        String endTime11 = sdf.format(d)+" 17:59:59";
        int sum1 = submissionService.sum1(startTime11,endTime11);

        int sum2 = submissionService.sum2(startTime11,endTime11);
        int sum11 = sum1 + sum2;
        int sum3 = submissionService.sum3(startTime11,endTime11);
        int sum4 = submissionService.sum4(startTime11,endTime11);
        int sum5 = submissionService.sum5(startTime11,endTime11);
        int sum6 = sum4 + sum5;
        int sum7 = submissionService.sum6(startTime11,endTime11);
        int sum8 = submissionService.sum7(startTime11,endTime11);
        int sum9 = submissionService.sum8(startTime11,endTime11);
        int sum10 = sum8 + sum9;


        /**
         * 以前-昨天 17:30:00
         */
        String startTime12 = sdf.format(addDateDays(d,-20000))+" 18:00:00";
        String endTime12 = sdf.format(addDateDays(d,-1))+" 17:59:59";
        System.out.println("startTime12:"+startTime12);
        int sum12 = submissionService.sum9(startTime12,endTime12);
        int sum13 = submissionService.sum10(startTime12,endTime12);
        int sum14 = sum12 + sum13;

        int sum15 = submissionService.sum11(startTime12,endTime12);
        int sum16 = submissionService.sum12(startTime12,endTime12);
        int sum17 = sum15 +sum16;

        /**
         * 2、后
         */

        int sum24 = submissionService.sum17(startTime12,endTime12,startTime11,endTime11);
        int sum25 = submissionService.sum18(startTime12,endTime12,startTime11,endTime11);


        int sum26 = sum14+sum24;
        int sum27 = sum17+sum25;

        int sum18 = submissionService.sum13(endTime11);
        int sum19 = submissionService.sum14(endTime11);
        int sum20 = sum18 + sum19;
        int sum21 = submissionService.sum15(endTime11);
        int sum22 = submissionService.sum16(endTime11);
        int sum23 = sum21 + sum22;
        WXPayUtil wxPayUtil = new WXPayUtil();
        Map map = new HashMap();
        String idNotice = "111";
        //String idNotice = "94";
        String content = null;
        content = "今日投诉汇报：1、"+str1+"，共接到投诉"+sum11+"条，其中电子支付"+sum1+"条，已处理"+sum3+"条，未处理"+sum6+"条；充电业务"+sum2+"条，已处理"+sum7+"条，未处理"+sum10+"条。2、昨日遗留投诉电子支付"+sum26+"条，充电业务"+sum27+"条，今日处理后仍遗留未处理投诉：电子支付"+sum14+"条，充电业务"+sum17+"条,3、截止今日18:00:00前，共遗留未处理投诉：电子支付"+sum20+"条，充电业务"+sum23+"条。";
        String keyid = "2";
        String random_number = wxPayUtil.generateNonceStr();
        String time_stamp = String.valueOf(System.currentTimeMillis());
        String key = "EL6UjSc4U1it6vaFrQ9GlGiMicEbRc0P";
        //通知编号
        map.put("id",idNotice);
        //通知内容
        map.put("content",content);
        //keyid
        map.put("keyid",keyid);
        //随机数
        map.put("random_number",random_number);
        //时间戳
        map.put("time_stamp",time_stamp);
        String sign = wxPayUtil.generateSignature(map,key);
        String url = "http://120.77.182.149:8999/OpenApi/tyxNotice";
        System.out.println(url);
        String data = "id="+idNotice+"&content="+content+"&keyid="+keyid+"&random_number="+random_number+"&time_stamp="+time_stamp+"&sign="+sign;

        RestUtil restUtil = new RestUtil();
        restUtil.interfaceUtil(url,data);

        return ResponseBo.ok();
    }


    /**
     * 投诉系统发送短信给客户
     * @return
     * @throws Exception
     */
                /* 乘客您好：您从${from}上车至${to}下车因未规范扫码导致扣费至全程，经核实现已退费${amount}元原路返回您的${accountname}账户3-5个工作日到账。
        温馨提示，三亚公交车辆分为一票制和分段收费制，乘坐一票制车辆上车只需扫码一次，下车无需扫码。乘坐分段收费车辆，上下车都需扫码，如下次因您个人
        失误不扫码或扫码不成功，均无法给予退费。感谢理解与支持！ */
    @RequestMapping("submission/febsNotice")
    @ResponseBody
    public ResponseBo febsNotice(String id,String from,String to,String amount,String accountname,String phone) throws Exception {

        WXPayUtil wxPayUtil = new WXPayUtil();
        Map map = new HashMap();
        String idNotice = "110";
        String keyid = "2";
        String random_number = wxPayUtil.generateNonceStr();
        String time_stamp = String.valueOf(System.currentTimeMillis());
        String key = "EL6UjSc4U1it6vaFrQ9GlGiMicEbRc0P";
        //通知编号
        map.put("id",idNotice);
        //通知内容
        map.put("from",from);
        map.put("to",to);
        map.put("amount",amount);
        map.put("accountname",accountname);
        //keyid
        map.put("keyid",keyid);
        //电话号码
        map.put("phone",phone);
        //随机数
        map.put("random_number",random_number);
        //时间戳
        map.put("time_stamp",time_stamp);
        String sign = wxPayUtil.generateSignature(map,key);
        String url = "http://120.77.182.149:8999/OpenApi/febsNotice";
        System.out.println(url);
        String data = "id="+idNotice+"&phone="+phone+"&from="+from+"&to="+to+"&amount="+amount+"&accountname="+accountname+"&keyid="+keyid+"&random_number="+random_number+"&time_stamp="+time_stamp+"&sign="+sign;
        RestUtil restUtil = new RestUtil();
        restUtil.interfaceUtil(url,data);
        SubmissionEntry submissionEntry = new SubmissionEntry();
        submissionEntry.setId(id);
        String context = "乘客您好：您从"+from+"上车至"+to+"下车因未规范扫码导致扣费至全程，" +
                "经核实现已退费"+amount+"元原路返回您的"+accountname+"账户3-5个工作日到账。 温馨提示，" +
                "三亚公交车辆分为一票制和分段收费制，乘坐一票制车辆上车只需扫码一次，下车无需扫码。" +
                "乘坐分段收费车辆，上下车都需扫码，如下次因您个人 失误不扫码或扫码不成功，均无法给予退费。感谢理解与支持！";
        submissionEntry.setFeedback(context);
        submissionService.updateSubmission(submissionEntry);
        return ResponseBo.ok();
    }

    @Log("优先处理数量")
    @RequestMapping("submission/first")
    @ResponseBody
    public PullDown first(){
        PullDown pullDown = new PullDown();
        if(cityparvm.equals("40")){
            pullDown.setSubmissionValue(submissionService.sumFirst());
        }else if(cityparvm.equals("41")){
            pullDown.setSubmissionValue(submissionService.sumFirst1());
        }
        return pullDown;


    }

    /**
     * 对日期的【天】进行加/减
     *
     * @param date 日期
     * @param days 天数，负数为减
     * @return 加/减几天后的日期
     */
    public static Date addDateDays(Date date, int days) {
        DateTime dateTime = new DateTime(date);
        return (Date) dateTime.plusDays(days).toDate();
    }
}
